<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="header-box">
          <div class="header">
            <div class="dot"></div>
            公司信息
          </div>
          <div class="company-box">
            <div class="company-info">
              <div>
                <i class="el-icon-s-home"></i>公司名称：{{ companyInfo.name }}
              </div>
              <div>
                <i class="el-icon-s-promotion"></i>公司地址：{{
                  companyInfo.address
                }}
              </div>
              <div>
                <i class="el-icon-phone"></i>联系电话：{{ companyInfo.phone }}
              </div>
            </div>
            <div class="statistics-box">
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/332206bff145a42efadc0ac688997642.png"
                  class="img"
                />
                <div>
                  <div class="title">公司排名</div>
                  <div class="num">{{ ranking }}</div>
                </div>
              </div>
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/333c32292d06bb2202d3eb1496ac77e6.png"
                  class="img"
                />
                <div>
                  <div class="title">公司总人数</div>
                  <div class="num">{{ companyInfo.team_count }}</div>
                </div>
              </div>
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/e29c9218929e8240fd9e22d39e77e22c.png"
                  class="img"
                />
                <div>
                  <div class="title">首充数量</div>
                  <div class="num">{{ companyInfo.sale_save_count }}</div>
                </div>
              </div>
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/73c30624d13d8a408f534aff1525028b.png"
                  class="img"
                />
                <div>
                  <div class="title">绑定人</div>
                  <div class="text">{{ companyInfo.real_name }}</div>
                </div>
              </div>
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/465743c3e72c755aff8fbcad0706a8f5.png"
                  class="img"
                />
                <div>
                  <div class="title">所在区县</div>
                  <div class="text">{{ companyInfo.area_name }}</div>
                </div>
              </div>
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/90eec6c606440f0a38a102af0d8edc74.png"
                  class="img"
                />
                <div>
                  <div class="title">开卡数量</div>
                  <div class="num">{{ companyInfo.sale_count }}</div>
                </div>
              </div>
              <div class="item">
                <img
                  src="https://tv.ytuy.cn/uploads/def/20240318/3dcc65b724ea42d37e5f89b0fe4070d1.png"
                  class="img"
                />
                <div>
                  <div class="title">激活数量</div>
                  <div class="num">{{ companyInfo.sale_open_count }}</div>
                </div>
              </div>
              <div class="item" />
            </div>
          </div>
        </div>
        <div class="header">
          <div class="dot"></div>
          公司成员
        </div>
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        name="m1"
        :row-key="
          row => {
            return row.id;
          }
        "
      >
        <el-table-column prop="real_name" label="员工姓名" />
        <el-table-column prop="sex" label="性别" min-width="50">
          <template slot-scope="scope">
            <span v-if="scope.row.sex == 1">男</span
            ><span v-else-if="scope.row.sex == 2">女</span
            ><span v-else>未知</span>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="联系电话" />
        <el-table-column prop="status" label="注册状态">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" style="color:#e6a23c;">
              未注册
            </div>
            <div v-else-if="scope.row.status == 1" style="color: #67c23a;">
              已注册
            </div>
            <div v-else-if="scope.row.status == 2" style="color:#f56c6c;">
              已删除
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="sale_count" label="开卡数量" min-width="100" />
        <el-table-column
          prop="sale_open_count"
          label="激活数量"
          min-width="100"
        />
        <el-table-column
          prop="sale_save_count"
          label="首充数量"
          min-width="100"
        />
        <el-table-column
          prop="sale_save_count"
          label="首充数量"
          min-width="100"
        />
        <el-table-column prop="ranking" label="业绩排名">
          <template slot-scope="scope">
            {{
              tableFrom.limit * (tableFrom.page - 1) + scope.$index + 1
            }}</template
          >
        </el-table-column>
        <el-table-column prop="address" label="家庭地址" />
      </el-table>

      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
import { companyDetail, companyUserList } from "@/api/company.js";
export default {
  name: "",
  data() {
    return {
      tableFrom: {
        page: 1,
        limit: 20,
        id: ""
      },
      listLoading: false,
      tableData: {
        data: [],
        total: 0
      },
      companyInfo: {
        sale_count: 0,
        rank: 0,
        sale_open_count: 0,
        sale_save_count: 0,
        team_count: 0
      },
      ranking: null
    };
  },
  watch: {},
  computed: {},
  methods: {
    // 列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num || this.tableFrom.page;
      this.tableData.data = [];

      let param = this.tableFrom;
      companyUserList(param)
        .then(res => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.count;
          this.listLoading = false;
        })
        .catch(res => {
          this.listLoading = false;
          this.$message.error(res.message);
        });
    },
    getCompanyDetail() {
      companyDetail(this.tableFrom.id)
        .then(res => {
          this.$set(this, "companyInfo", res.data);
        })
        .catch(e => {
          this.$message.error(e);
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList("");
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList("");
    }
  },
  created() {},
  mounted() {
    if (this.$route.query.id) {
      this.tableFrom.id = this.$route.query.id;
      this.ranking = this.$route.query.ranking;
      this.getCompanyDetail();
      this.getList(1);
    }
  }
};
</script>

<style lang="scss" scoped>
.header-box {
  margin-bottom: 16px;
}
.header {
  display: flex;
  width: 100%;
  height: 61px;
  align-items: center;
  line-height: 24px;
  padding-left: 27px;
  font-size: 18px;
  color: #333333;
  border-bottom: 1px solid #eeeeee;

  .dot {
    width: 10px;
    height: 10px;
    border-radius: 5px;
    margin-right: 4px;
    background: #385be1;
  }
}

.company-box {
  display: flex;
  width: 100%;
  height: 221px;
  .company-info {
    display: flex;
    flex: 1.2;
    flex-direction: column;
    justify-content: space-around;
    background: url("https://tv.ytuy.cn/uploads/def/20240318/f69d0320293ee4c344e236f58e55c44d.png");
    background-size: 100% 100%;
    padding-left: 16px;
    width: 728px;
    height: 100%;
    border-radius: 16px;
    font-size: 16px;
    color: #ffffff;
    i {
      margin-right: 4px;
    }
  }
  .statistics-box {
    flex: 2;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 44px;
    .item {
      display: flex;
      width: 25%;
      box-sizing: border-box;
      .img {
        height: 44px;
        width: 44px;
        margin-right: 14px;
      }
      .title {
        font-size: 18px;
        color: #aeb6d6;
      }
      .num {
        font-size: 22px;
      }
      .text {
        font-size: 16px;
      }
    }
  }
}
</style>
